package video

import (
	"app-api/clients/video"
	"context"
	"github.com/jinzhu/copier"

	"app-api/app/internal/svc"
	"app-api/app/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetVideoDetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetVideoDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetVideoDetailLogic {
	return &GetVideoDetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetVideoDetailLogic) GetVideoDetail(req *types.VideoIDRequest) (resp *types.VideoInfo, err error) {
	v, err := l.svcCtx.VideoRPC.GetVideo(l.ctx, &video.VideoIDRequest{VideoId: req.VideoID})
	if err != nil {
		return nil, err
	}

	resp = &types.VideoInfo{}
	_ = copier.Copy(resp, v)
	return resp, nil
}
